package com.hgc.boot01.controller;

import com.hgc.boot01.pojo.User;
import com.hgc.boot01.service.HelloService;
import com.hgc.boot01.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    //根据类型查找
    private UserService userService;


    @RequestMapping("/users")
    public List<User> findAll() {
        List<User> userList = userService.findAll();
        return userList;
    }

    @RequestMapping("/save1")
    public int save1(User user) {
        System.out.println("save1:"+user);
        return userService.saveUser(user);
    }
    @RequestMapping("/save2")
    public int save2( @RequestBody User user) {
        System.out.println("save2:"+user);
        return userService.saveUser(user);
    }


    @RequestMapping("/get/{id}")
    public  User getById(@PathVariable String id) {
        User user = userService.getById(id);
        System.out.println("User:"+user);
        return user;
    }


    @RequestMapping("/update")
    public  int update(@RequestBody User user) {
        System.out.println("update:"+user);
        return userService.updateUser(user);
    }

    @RequestMapping("/pages")
    public Map pages(int currentPage, int pageSize , String val) {

        return userService.findAllByPage(val, currentPage, pageSize);
    }


}
